﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AddInDesignerObjects;
using Microsoft.Office.Core;
using WPSPropertyPlugin.Objects;
using WPSPropertyPlugin.Shapes;

namespace WPSPropertyPlugin
{
  public class WPPPlugin : IDTExtensibility2, IRibbonExtensibility
  {
    public static WPSApplication WPSApplication { get; set; }
    public static frmProperty PropertyForm = null;

    public static void Reset()
    {
      Shapes.WordShapeObject.Reset();
    }

    public static string GetShapeConfigByName(string shapeName)
    {
      switch (WPSApplication.ApplicationType)
      {
        case WPSApplicationTypes.Word:
          return WordShapeObject.GetShapeConfigByName(shapeName);

        case WPSApplicationTypes.PowerPoint:
          break;
      }
      return null;
    }

    public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
    {
      WPSApplication = new WPSApplication(Application);
    }

    public void OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom)
    {
    }

    public void OnAddInsUpdate(ref Array custom)
    {
    }

    public void OnStartupComplete(ref Array custom)
    {
    }

    public void OnBeginShutdown(ref Array custom)
    {
      if (PropertyForm != null && !PropertyForm.IsDisposed)
      {
        PropertyForm.Close();
        PropertyForm = null;
      }
    }

    /// <summary>
    /// 显示属性窗口
    /// </summary>
    public void ShowPropertyForm(IRibbonControl ctl)
    {
      if (PropertyForm == null)
      {
        PropertyForm = new frmProperty(WPSApplication);
      }
      PropertyForm.Show();
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="ctl"></param>
    /// <returns></returns>
    public Bitmap GetRibbonImage(IRibbonControl ctl)
    {
      return Resources.showPropertyPlugin;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="ribbonID"></param>
    /// <returns></returns>
    public string GetCustomUI(string ribbonID)
    {
      return Resources.RibbonConfig;
    }
  }
}
